package com.example.footballsystem.controller;

import com.example.footballsystem.entity.Tran;
import com.example.footballsystem.mapper.TranMapper;
import com.example.footballsystem.service.TranSercice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/Tran")
@CrossOrigin(origins = "*")
public class TranController {
    @Autowired
    TranSercice tranSercice;
    @GetMapping("/getUserTodayTran")
    public ResponseEntity<List<Tran>> getUserTodayTran(String userID){
        log.info("getUserTodayTran"+tranSercice.getTodayTran(userID).toString());
        return ResponseEntity.ok().body(tranSercice.getTodayTran(userID));
    }
    @GetMapping("/getUserTodayFinishTran")
    public ResponseEntity<List<Tran>> getUserTodayFinishTran(String userID,Boolean finish){
        return ResponseEntity.ok().body(tranSercice.getTodayFinishTran(userID,finish));
    }
    @PostMapping("/addTran")
    public ResponseEntity<Boolean> addTran(@RequestBody Tran tran){
        log.info("add tran "+tran.toString());
        return ResponseEntity.ok().body(tranSercice.addTran(tran));
    }
    @GetMapping("/finishTran")
    public ResponseEntity<Boolean> finishTran(String account,String title){
        log.info("finish tran "+account +" "+title);
        return ResponseEntity.ok().body(tranSercice.finishTran(account,title));
    }
    @GetMapping("getTranCount")
    public ResponseEntity<List<Integer>> getTranCount(){
        return ResponseEntity.ok().body(tranSercice.getTranCount());
    }
    @GetMapping("count")
    public ResponseEntity<Integer> getCount(){
        return ResponseEntity.ok().body(tranSercice.count());
    }
}
